package com.test2;


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.devtools.HasDevTools;
import org.openqa.selenium.devtools.v113.log.Log;
import org.openqa.selenium.remote.Augmenter;

import java.util.concurrent.TimeUnit;

/**
 * @author kk
 * @Description Selenium DevTools功能演示
 */
public class SeleniumDevTools2 {

    public static void main(String[] args) throws InterruptedException {
        String webDriverDir = "浏览器驱动路径";
        // 加载驱动
        System.setProperty("webdriver.chrome.driver", "C:\\\\Program Files\\\\Google\\\\Chrome\\\\Application\\\\chromedriver.exe");
        // 创建驱动对象
        WebDriver driver = new ChromeDriver();

        driver = new Augmenter().augment(driver);
        DevTools devTools = ((HasDevTools) driver).getDevTools();
        devTools.createSession();

        devTools.send(Log.enable());
        devTools.addListener(Log.entryAdded(),
                logEntry -> {
                    System.out.println("log: "+logEntry.getText());
                    System.out.println("level: "+logEntry.getLevel());
                });


        driver.get("https://www.baidu.com/");

        TimeUnit.MILLISECONDS.sleep(45000);
    }
}
